<template>
    <el-dialog
            :title="!dataForm.orderId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="主键ID" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="主键ID"></el-input>
                </el-form-item>
                <el-form-item label="船舶ID" prop="vesselId">
                        <el-input v-model="dataForm.vesselId" placeholder="船舶ID"></el-input>
                </el-form-item>
                <el-form-item label="预计到港时间" prop="estimatedArrivalTime">
                        <el-date-picker
                                v-model="dataForm.estimatedArrivalTime"
                                type="datetime"
                                placeholder="预计到港时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="预计离港时间" prop="estimatedDepartureTime">
                        <el-date-picker
                                v-model="dataForm.estimatedDepartureTime"
                                type="datetime"
                                placeholder="预计离港时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="实际到港时间" prop="actualArrivalTime">
                        <el-date-picker
                                v-model="dataForm.actualArrivalTime"
                                type="datetime"
                                placeholder="实际到港时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="实际离港时间" prop="actualDepartureTime">
                        <el-date-picker
                                v-model="dataForm.actualDepartureTime"
                                type="datetime"
                                placeholder="实际离港时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="抵港标志" prop="arrivalFlag">
                        <el-input v-model="dataForm.arrivalFlag" placeholder="抵港标志"></el-input>
                </el-form-item>
                <el-form-item label="离港标志" prop="departureFlag">
                        <el-input v-model="dataForm.departureFlag" placeholder="离港标志"></el-input>
                </el-form-item>
                <el-form-item label="计划状态（如正常、调整、重置）" prop="planStatus">
                        <el-input v-model="dataForm.planStatus" placeholder="计划状态（如正常、调整、重置）"></el-input>
                </el-form-item>
                <el-form-item label="创建时间" prop="createdAt">
                        <el-date-picker
                                v-model="dataForm.createdAt"
                                type="datetime"
                                placeholder="创建时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="更新时间" prop="updatedAt">
                        <el-date-picker
                                v-model="dataForm.updatedAt"
                                type="datetime"
                                placeholder="更新时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="航次载运装卸集装箱信息" prop="containerInfo">
                        <el-input v-model="dataForm.containerInfo" placeholder="航次载运装卸集装箱信息"></el-input>
                </el-form-item>
                <el-form-item label="进口舱单信息" prop="importManifest">
                        <el-input v-model="dataForm.importManifest" placeholder="进口舱单信息"></el-input>
                </el-form-item>
                <el-form-item label="船图信息" prop="shipDiagram">
                        <el-input v-model="dataForm.shipDiagram" placeholder="船图信息"></el-input>
                </el-form-item>
                <el-form-item label="船舶移泊计划" prop="movePlan">
                        <el-input v-model="dataForm.movePlan" placeholder="船舶移泊计划"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            id: null,
            vesselId: null,
            estimatedArrivalTime: null,
            estimatedDepartureTime: null,
            actualArrivalTime: null,
            actualDepartureTime: null,
            arrivalFlag: null,
            departureFlag: null,
            planStatus: null,
            createdAt: null,
            updatedAt: null,
            containerInfo: null,
            importManifest: null,
            shipDiagram: null,
            movePlan: null
          },
          dataRule: {
            id: [
                        { required: true, message: '主键ID不能为空', trigger: 'blur' }
            ],
            vesselId: [
                        { required: true, message: '船舶ID不能为空', trigger: 'blur' }
            ],
            estimatedArrivalTime: [
                        { required: true, message: '预计到港时间不能为空', trigger: 'blur' }
            ],
            estimatedDepartureTime: [
                        { required: true, message: '预计离港时间不能为空', trigger: 'blur' }
            ],
            actualArrivalTime: [
                        { required: true, message: '实际到港时间不能为空', trigger: 'blur' }
            ],
            actualDepartureTime: [
                        { required: true, message: '实际离港时间不能为空', trigger: 'blur' }
            ],
            arrivalFlag: [
                        { required: true, message: '抵港标志不能为空', trigger: 'blur' }
            ],
            departureFlag: [
                        { required: true, message: '离港标志不能为空', trigger: 'blur' }
            ],
            planStatus: [
                        { required: true, message: '计划状态（如正常、调整、重置）不能为空', trigger: 'blur' }
            ],
            createdAt: [
                        { required: true, message: '创建时间不能为空', trigger: 'blur' }
            ],
            updatedAt: [
                        { required: true, message: '更新时间不能为空', trigger: 'blur' }
            ],
            containerInfo: [
                        { required: true, message: '航次载运装卸集装箱信息不能为空', trigger: 'blur' }
            ],
            importManifest: [
                        { required: true, message: '进口舱单信息不能为空', trigger: 'blur' }
            ],
            shipDiagram: [
                        { required: true, message: '船图信息不能为空', trigger: 'blur' }
            ],
            movePlan: [
                        { required: true, message: '船舶移泊计划不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.orderId = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.orderId = id || 0
            if (this.dataForm.orderId) {
              this.$http({
                url: this.$http.adornUrl(`/app/AppVesselPlan/info/\\$\\{this.dataForm.orderId}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appvesselplan
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/AppVesselPlan/\\$\\{!this.dataForm.orderId ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>